<div class="main_item ">
<?php 
if(isset($this->list_place)){
	foreach ($this->list_place as $key => $value) {
		echo '<div class="place item item_place">';
		echo '<div class="name_item">' . $value['name'] . '</div>';
		echo '<div class="item_detail"> Địa chỉ : '. $value['address'] . ', ' . $value['steet'] . ', ' . $value['city'] .'</div>';
		echo '<span><a class="show_hide" data-id="' . $value['id'] . '"><i class="fa fa-angle-double-down"></i></a></span>';	

		$list_wifi = $this->model->get_all_wifi($value['id']);
		foreach ($list_wifi as $key_wifi => $value_wifi) {
			$data_value = 0;
			if($value_wifi['rate'] == 100) $data_value = 100;
			else if (50 < $value_wifi['rate'] && $value_wifi['rate'] < 100) $data_value = 70;
			else if (30 < $value_wifi['rate'] && $value_wifi['rate'] < 50) 	$data_value = 30;
			else if ($value_wifi['rate'] == 50) $data_value = 50;
			else if ($value_wifi['rate'] < 30) $data_value = 0;

			echo '<div class="item_wifi">';
			echo '<div class="wifi_detail">';
		    echo '<div class="wifi_name">Wifi name : ' . $value_wifi['name'] . '</div>';
			echo '<div class="wifi_pass">Password : ' . $value_wifi['password'] . '</div>';
			echo '<div class="wifi_pin">Pin :' . $value_wifi['pin'] . '</div>';
			echo '</div>';
			echo '<div class="rank">';
			echo '<div class="title_rate">Did this wifi work?</div>';
			echo '<i data-func="unvote" data-wifi="' . $value_wifi['id'] . '" class="fa fa-times-circle fa-2x unvote"></i><i data-wifi="' . $value_wifi['id'] . '" data-func="vote" class="vote fa fa-check-circle fa-2x"></i>';
			echo '</div>';
			echo '<div class="rating"><span class="rated" data-value="' . $data_value . '">' . $value_wifi['rate'] . '% working </span>';
			echo '<span class="total_rate" data-total="' . $value_wifi['total'] . '" data-votes="' . $value_wifi['votes'] . '">' . $value_wifi['total'] . ' votes</span>';
			echo '<span class="last_time">' . $value_wifi['last_date'] . $value_wifi['title_last_date'] . '</span>';
			echo '</div>';
			echo '<div class="clear"></div>';
			echo '</div>';
		}

		echo '<div class="clear"></div></div><hr>';
	}
} else {
	echo '<div class="place item item_place">';
	echo '<div class="name_item">no item<hr></div>';
	echo '</div>';
}
?>
</div>
<div class="left_item">
	
</div>				
<script type="text/javascript">
	$(document).ready(function() {
		$('.show_hide').clickToggle(function(event) {
			 /* ngược lại */
            var parten = $(this).children();
            var $this = $(this).parent().parent(); 
            $this.children( '.item_wifi' ).fadeOut(2000);
           	$(this).parent().parent().animate({ 'min-height': 50 }, 1000
				, function() {
					parten.removeClass('fa-angle-double-up');
            		parten.addClass('fa-angle-double-down');
			}).delay(500);
            return false;
			
		}, function() {
		 	var parten = $(this).children();
            var $this = $(this).parent().parent(); 
			$this.animate({ 'min-height': 50 }, 900 , 
				function() {
					$this.children('.item_wifi').fadeIn(2000).delay(300);
					parten.removeClass('fa-angle-double-down');
            		parten.addClass('fa-angle-double-up');
				});

			/*{ name: "John" }*/

			return false;
        });

	});
	$('.item_place').on('click','.vote, .unvote',function() {
			
			var id 		= $(this).data('wifi');
			var action 	= $(this).data('func');
			var url 	= '<?php echo URL; ?>Places/' + action;
			var pdata 	= {id_wifi : id};
			var $this 	= $(this).parent().parent(); 

			$.post(url, pdata, function(o) {

				if(o[0] == true)
				{
					$this.fadeOut(2000).delay(500);
				}else {
					$this.empty();
					$.each(o, function( index, value ) {
						data_value = 0;
						if(value['rate'] == 100) data_value = 100;
						else if (50 < value['rate'] && value['rate'] < 100) data_value = 70;
						else if (30 < value['rate'] && value['rate'] < 50) 	data_value = 30;
						else if (value['rate'] == 50) data_value = 50;
						else if (value['rate'] < 30) data_value = 0;	     	

		     			$this.append(
		     				'<div class="wifi_detail">'
		     			    +'<div class="wifi_name">Wifi name : '+value['name']+'</div>'
		     				+'<div class="wifi_pass">Password : '+value['password']+'</div>'
		     				+'<div class="wifi_pin">Pin :'+value['pin']+'</div>'
		     				+'</div>'
		     				+'<div class="rank">'
		     				+'<div class="title_rate">Did this wifi work?</div>'
		     				+'<i data-func="unvote" data-wifi="' + value['id'] + '" class="fa fa-times-circle fa-2x unvote"></i><i data-wifi="' + value['id'] + '" data-func="vote" class="vote fa fa-check-circle fa-2x"></i>'
		     				+'</div>'
		     				+'<div class="rating"><span class="rated" data-value="'+ data_value +'">'+ value['rate'] +'% working </span>'
		     				+'<span class="total_rate" data-total="'+ value['total'] +'" data-votes="'+ value['votes'] +'">'+ value['total'] +' votes</span>'
		     				+'<span class="last_time">'+ value['last_date'] +value['title_last_date'] +'</span>'
		     				+'</div>'
		     				+'<div class="clear"></div>'
	     				);
					});
				}
			},'json').fail(function(jqXHR, textStatus, errorThrown){
				//fail
				$('.loadding').css('display','none');
			});
	});
</script>
